#include "common.h"

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
	int fd[2];
	pid_t pid;

	if(pipe(fd) < 0)
		err_sys("pipe error\n");

	pid = fork();
	if(pid < 0)
		err_sys("frok error\n");
	else if(pid == 0)
	{
		close(fd[0]);
	
		int buf = 9;
		sleep(1);
		write(fd[1], &buf, 10);
		
		dup2(fd[1], 1);

		execlp("expr", "expr", "4", "+", "5", NULL);
		exit(0);
	}
	else
	{
		close(fd[1]);
 
		int buf;
		printf("parent read start...\n"); 

		read(fd[0], &buf, 10);

		printf("output : %d\n", buf);
		exit(0);
	}

	return 0;
}
